<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

Class Setting extends CI_Controller{
    function __construct()
	{
		parent::__construct();
		
		$this->load->database();
		$this->load->helper('url');
		
		$this->load->library('grocery_CRUD');	
    }
	
	function _example_output($output = null)
	{
		$this->load->view('setting.php',$output);	
	}
        function index()
	{
		$this->_example_output((object)array('output' => '' , 'js_files' => array('') , 'css_files' => array()));
	}

        function encrypt_password($post_array, $primary_key = null)
        {
          
                $this->load->helper('security');
                $post_array['PASSWORD'] = do_hash($post_array['PASSWORD'], 'md5');
                $post_array['PASSWORD2'] = do_hash($post_array['PASSWORD2'], 'md5');
                return $post_array;
          
        }
        
        function auth()
        {
            $crud = new grocery_CRUD();
            $crud->set_table('__auth');
            $crud->columns('USERNAME','STATUS_USER','PASSWORD','PASSWORD2','LG_ID');
            $crud->display_as('USERNAME', 'User')
                    ->display_as('LG_ID','Group')
                    ->display_as('PASSWORD','Password Desktop')
                    ->display_as('STATUS_USER','Status')
                    ->display_as('PASSWORD2','Password Web');
                    
            $crud->change_field_type('PASSWORD', 'invisible');
            $crud->change_field_type('STATUS_USER', 'enum', array( '1', '2' ));
            $crud->set_subject('User');
            $crud->set_relation('LG_ID','__login_group','LG_NAME');        
            $crud->callback_before_insert(array($this,'encrypt_password'));
            $output = $crud->render();
            $this->_example_output($output);
        }
        
        function privileges()
        {
            $crud = new grocery_CRUD();
            $crud->set_table('__hak_akses');
            $crud->columns('HA_ID','HA_MENU','LG_ID','HA_LEVEL');
            $crud->display_as('HA_ID','Id')
                    ->display_as('HA_MENU','Menu');
            $crud->set_subject('Hak Akses');
            $crud->set_relation('LG_ID','__login_group','LG_NAME');
            $output = $crud->render();
            $this->_example_output($output);
        }
        
        function groups()
        {
            $crud = new grocery_CRUD();
            $crud->set_table('__login_group');
            $crud->columns('LG_ID','LG_NAME','LG_DESC');
            $crud->display_as('LG_ID','ID')
                    ->display_as('LG_NAME','Group')
                    ->display_as('LG_DESC','Deskripsi');
            $output = $crud->render();
            $this->_example_output($output);   
        }
}